﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;

namespace HeyoUi.Converter
{
    [ValueConversion(typeof(bool), typeof(Visibility))]
    public class InBoolToVisibilityConverter : IValueConverter
    {
        public InBoolToVisibilityConverter()
            : this(true)
        {

        }
        public InBoolToVisibilityConverter(bool collapsewhenInvisible)
            : base()
        {
            CollapseWhenInvisible = collapsewhenInvisible;
        }
        public bool CollapseWhenInvisible { get; set; }

        public Visibility FalseVisible => CollapseWhenInvisible ? Visibility.Collapsed : Visibility.Hidden;

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
                return Visibility.Visible;
            return (bool)value ? FalseVisible : Visibility.Visible;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
                return true;
            return ((Visibility)value != Visibility.Visible);
        }
    }
}
